package com.janwen.interview.j2se;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * http://weibo.com/1915548291/z6ljHCpLu#1353601051646
 * 
 * @author janwen Nov 23, 2012 String常见比较
 */
public class StringEquals {

	static final Log logger = LogFactory.getLog(StringEquals.class);

	public static void main(String[] args) {
		strEq6();
	}

	static void strEq1() {
		String a = "a1";
		String b = "a" + 1;
		logger.info(a == b);
	}

	static void strEq2() {
		String a = "ab";
		String b = "b";
		String c = "a" + b;
		logger.info(a == c);
	}

	static void strEq3() {
		String a = "ab";
		final String b = "b";
		String c = "a" + b;
		logger.info(a == c);
	}
	private static String getBB() {
		return "b";
	}
	static void strEq4() {
		String a = "ab";
		final String b = getBB();
		String c = "a" + b;
		logger.info(a == c);
	}

	private static String con = "ab";

	static void strEq5() {
		String a = "a";
		String b = "b";
		String c = a + b;
		logger.info(c == con);
		logger.info(con.intern() == c);
	}
	
	private static String con_ref = new String("ab");
	static void strEq6() {
		String a = "a";
		String b = "b";
		String c = a + b;
		logger.info(c == con_ref);
		logger.info(c.intern() == con_ref);
		logger.info(c.intern() == con_ref.intern());
	}

	
}
